// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;

namespace SnapObjects.Data.Oracle
{
    /// <summary>
    ///     Contains the Oracle extension methods that enable you to use an <see cref="IDataContextOptions{TAdoDbContext}"/> object to 
    ///     configure the context to connect to an Oracle database.
    /// </summary>
    public static class OracleExtensions
    {
        /// <summary>
        ///     Configures the context to connect to an Oracle database.
        /// </summary>
        /// <typeparam name="TAdoDbContext">The type of context to be configured.</typeparam>
        /// <param name="contextOptions">The options being used to configure the context.</param>
        /// <param name="connectionString">
        ///     A string containing connection information about how to connect to the data source.
        /// </param>
        /// <returns>
        ///     An <see cref="IDataContextOptions{TAdoDbContext}"/> object which contains options of the DataContext object.
        /// </returns>
        public static IDataContextOptions<TAdoDbContext> UseOracle<TAdoDbContext>(
            this IDataContextOptions<TAdoDbContext> contextOptions, string connectionString)
            where TAdoDbContext : OracleDataContext
        {
            contextOptions = new OracleDataContextOptions<TAdoDbContext>(connectionString);

            return contextOptions;
        }

        /// <summary>
        ///     Configures the context to connect to an Oracle database.
        /// </summary>
        /// <typeparam name="TAdoDbContext">The type of context to be configured.</typeparam>
        /// <param name="contextOptions">The options being used to configure the context.</param>
        /// <param name="connectionString">
        ///     A string containing connection information about how to connect to the data source.
        /// </param>
        /// <param name="options">
        ///     (Optional) An action to allow additional Oracle-specific configuration.
        /// </param>
        /// <returns>
        ///     An <see cref="IDataContextOptions{TAdoDbContext}"/> object which contains options of the DataContext object.
        /// </returns>
        public static IDataContextOptions<TAdoDbContext> UseOracle<TAdoDbContext>(
            this IDataContextOptions<TAdoDbContext> contextOptions,
            string connectionString,
            Action<OracleDataContextOptions<TAdoDbContext>> options)
            where TAdoDbContext : OracleDataContext
        {
            contextOptions = new OracleDataContextOptions<TAdoDbContext>(connectionString);

            options?.Invoke((OracleDataContextOptions<TAdoDbContext>)contextOptions);

            return contextOptions;
        }
    }
}
